<?php
/**
 * Created by PhpStorm.
 * User: 王松
 * Time: 2017/7/10 14:33
 */

namespace App\Models\Observer;

use Illuminate\Database\Eloquent\Model;

abstract class ModelObserverAbstract
{
    protected $request;

    public function __construct()
    {
        $this->request = app('request');
    }

    /**
     * 清除缓存项目
     * @param \Illuminate\Database\Eloquent\Model $model
     */
    protected function removeCache(Model $model, $tags = null)
    {
        if ($tags) {
            \Cache::tags($tags)->flush();
        }

        \Cache::forget($model->getTable() . ':' . $model->getKeyName() . ':' . $model->getKey());
    }
}